
class BruteJob{
	public:
		BruteJob(Job _job, char *pattern){
			this->job = _job;
			this->current = new char[sizeof(this->job.rangeFrom)];
			strcpy(current, job.rangeFrom);
			this->gen = new Generator(pattern, this->current);
			// printf("%s\n", current);
		}

		typedef int( * BrutePasswordCheck )( char[] );

		void Run(BrutePasswordCheck pCheck){
			int length = strlen(job.rangeFrom);
			job.startTime = time(NULL);

			while(strcmp(current, job.rangeTo) != 0){
				gen->Next();
				if (pCheck(current)==1){
					job.endTime = time(NULL);
					job.isFinished = 1;
					job.success = 1;
					memcpy(job.foundPassword, current, length+1);
					return;
				}
			}
			job.endTime = time(NULL);
			job.success = 0;
			job.isFinished = 1;			
		}

		Job GetResult(){
			return job;
		}


	private:
		Generator *gen;
		Job job;
		char *current;
};
